package com.wuyan.locationdog.adapter

import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.LayoutRes
import com.arcsoft.commonbase.bean.DogFileBeanContent
import com.arcsoft.commonbase.ext.gone
import com.arcsoft.commonbase.ext.loadImageCircleCar
import com.arcsoft.commonbase.ext.visible
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.wuyan.locationdog.R
import com.wuyan.locationdog.help.DogHelp


class DeviceFilesListAdapter(@LayoutRes layoutResId: Int, data: MutableList<DogFileBeanContent>?) :
    BaseQuickAdapter<DogFileBeanContent, BaseViewHolder>(layoutResId, data) {


    override fun convert(holder: BaseViewHolder, item: DogFileBeanContent) {
        holder.apply {
            getView<ImageView>(R.id.dogImg).loadImageCircleCar(item.dogImg)
            getView<TextView>(R.id.dogName).text = item.dogName
            var desc = ""
            val textView = getView<TextView>(R.id.dogType)

            setDogDesc(textView, item)
//            SpanUtils.with(  getView<TextView>(R.id.dogType)).append()
//            getView<TextView>(R.id.dogType).text = item.dogType + " | " + item.age + " | " + item.weight + "kg"

            if (item.gender == "公") {
                getView<ImageView>(R.id.gender).setImageResource(R.mipmap.men)
            } else {
                getView<ImageView>(R.id.gender).setImageResource(R.mipmap.women)
            }

            if (item.deviceId.isNullOrEmpty()) {
                getView<ImageView>(R.id.isBindDevice).setImageResource(R.mipmap.bind_device_no)
            } else {
                getView<ImageView>(R.id.isBindDevice).setImageResource(R.mipmap.bind_device_yse)
            }
            if (DogHelp.isGoDetail) {
                getView<ImageView>(R.id.ivCheck).gone()
            } else {
                getView<ImageView>(R.id.ivCheck).visible()
                getView<ImageView>(R.id.isBindDevice).gone()
            }

            val imageView = getView<ImageView>(R.id.ivCheck)
            if (item.isSelect) {
                imageView.setImageResource(R.mipmap.alarm_checked)
            } else {
                imageView.setImageResource(R.mipmap.alarm_unchecked)
            }
        }
    }

}

fun setDogDesc(textView: TextView, item: DogFileBeanContent) {
    if (item.dogType.isNullOrEmpty() && !item.age.isNullOrEmpty() && !item.weight.isNullOrEmpty()) {
        textView.text = item.age + " | " + item.weight + "kg"
    }
    if (item.dogType.isNullOrEmpty() && item.age.isNullOrEmpty() && !item.weight.isNullOrEmpty()) {
        textView.text = item.weight + "kg"
    }
    if (item.dogType.isNullOrEmpty() && item.age.isNullOrEmpty() && item.weight.isNullOrEmpty()) {
        textView.text = ""
    }
    if (!item.dogType.isNullOrEmpty() && item.age.isNullOrEmpty() && item.weight.isNullOrEmpty()) {
        textView.text = item.dogType
    }
    if (!item.dogType.isNullOrEmpty() && !item.age.isNullOrEmpty() && item.weight.isNullOrEmpty()) {
        textView.text = item.dogType + " | " + item.age
    }
    if (!item.dogType.isNullOrEmpty() && !item.age.isNullOrEmpty() && !item.weight.isNullOrEmpty()) {
        textView.text = item.dogType + " | " + item.age + " | " + item.weight + "kg"
    }
    if (!item.dogType.isNullOrEmpty() && item.age.isNullOrEmpty() && !item.weight.isNullOrEmpty()) {
        textView.text = item.dogType + " | " + item.weight + "kg"
    }
}



